package com.bondex.charter.config;

import com.bondex.bondexapi.cas.service.CASVerifyLoginService;
import com.bondex.bondexapi.generator.service.GeneratorCodeService;
import com.bondex.global.spring.SpringContextHolder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

/**
 * 普通配置项
 *
 * @author JD
 */
@Configuration
//@AutoConfigureAfter({JdbcTemplateConfig.class, CasConfig.class})
public class CommonConfig {

	//region 引用相关

	//实现对spring context的管理
	@Bean
	@Lazy(false)
	public SpringContextHolder springContextHolder() {
		return new SpringContextHolder();
	}

	//endregion

	//region 流水号生成

	//@formatter:off
	@Value("${charter.GeneratorCode.url}") private String GENERATOR_CODE_URL;
	@Value("${charter.GeneratorCode.time_out}") private int GENERATOR_CODE_TIME_OUT;
	//@formatter:on

	@Bean
	public GeneratorCodeService generatorCodeService() {
		return new GeneratorCodeService(GENERATOR_CODE_URL, GENERATOR_CODE_TIME_OUT);
	}

	//endregion

	//region CAS相关

	@Value("${charter.cas.url}")
	private String CAS_URL;

	@Bean
	public CASVerifyLoginService casVerifyLoginService() {
		return new CASVerifyLoginService(CAS_URL);
	}

	//endregion

}
